package com.ml.mall.service.company.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ml.mall.bean.req.company.CompanyRemarkAddDto;
import com.ml.mall.consts.CommonConsts;
import com.ml.mall.entity.company.SysCompanyRemark;
import com.ml.mall.entity.sys.SysUser;
import com.ml.mall.security.JwtUtil;
import com.ml.mall.service.SysCompanyRemarkService;
import com.ml.mall.mapper.SysCompanyRemarkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class SysCompanyRemarkServiceImpl extends ServiceImpl<SysCompanyRemarkMapper, SysCompanyRemark>
    implements SysCompanyRemarkService{

    @Autowired
    private SysCompanyRemarkMapper sysCompanyRemarkMapper;

    @Override
    public Integer addCompanyRemark(CompanyRemarkAddDto dto) {

        SysUser currentUser = JwtUtil.getCurrentUser();

        //非管理员，只能为本公司添加备注
        if(!CommonConsts.ROLE_TYPE_ADMIN.equals(currentUser.getRoleType())){
            dto.setCompanyId(currentUser.getCompanyId());
        }

        SysCompanyRemark sysCompanyRemark = new SysCompanyRemark();
        BeanUtil.copyProperties(dto, sysCompanyRemark);
        sysCompanyRemark.setCreator(currentUser.getAcc());

        return sysCompanyRemarkMapper.insert(sysCompanyRemark);
    }
}




